https://leetcode.cn/problems/maximum-prime-difference/submissions/523330809/


class Solution {
public:

    bool is_prime(int x)
    {
        if (x == 1)
            return false;

        if (x == 2)
            return true;

        for (int i = 2; i * i <= x; i++)
            if (x % i == 0)
                return false;

        return true;
    }

    int maximumPrimeDifference(vector<int>& nums) {


        int left = 0;
        for (int i = 0; i < nums.size(); i++)
            if (is_prime(nums[i]))
            {
                left = i;
                break;
            }

        int right = 0;
        for (int i = nums.size() - 1; i >= 0; i--)
            if (is_prime(nums[i]))
            {
                right = i;
                break;
            }


        return (right - left);

    }
};